{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7fb5e93d",
   "metadata": {},
   "source": [
    "-------------------\n",
    "* 日期：2022-10-12 \\ week08\n",
    "* 课程：python\n",
    "* 记录人：Zouyimeng\n",
    "-------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3ffa09b",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "> 1. 有序的数据结构-字符串\n",
    ">> 1. 字符串的基本概念（回顾）\n",
    ">>> 1. \n",
    ">>> 2. \n",
    ">>> 3. \n",
    ">> 2.字符串的性质和方法\n",
    "> 2.有序的数据结构-列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1c1c9cbb",
   "metadata": {},
   "source": [
    "## 1.字符串的性质和方法\n",
    "\n",
    "* 字符串的性质\n",
    "> 1. 字符串的有序性\n",
    "> 2. 字符串是有长度的\n",
    ">> 1. 使用len（）检查字符串的长度\n",
    "* 字符串的基本方法(运算法则)\n",
    "> 1. 字符串的取值：str[index]\n",
    "> 2. 字符串的切片：str[start:stop] stop：取不到\n",
    "> 3. 字符串的拼接：+\n",
    "> 4. in 检查成员是否存在\n",
    "* 字符串的一般方法（function/Methods  函数/方法）\n",
    "> 1. isdigit()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "af24c70b",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"广州南方学院团委\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cd64180c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bbed28be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'委'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "64c4a205",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "string index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mtext\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m100\u001b[39;49m\u001b[43m]\u001b[49m\n",
      "\u001b[1;31mIndexError\u001b[0m: string index out of range"
     ]
    }
   ],
   "source": [
    "text[100]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ca749106",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "65c8dda5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0] + text[1] +text[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "095f256a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0:6] # 等价于 text[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "60f29bac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "97fbb5d8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a23f1782",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院团'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9c51691f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "4d8eabec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委广州南方学院团委广州南方学院团委'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41857580",
   "metadata": {},
   "source": [
    "* in 检查成员对象\n",
    "\n",
    "* count（）检查字符串出现的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "3d14a8fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州\" in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4e9cb8a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"北京\" in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "f69d9d40",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text.count(\"广州\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "562cf576",
   "metadata": {},
   "source": [
    "* isdigit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b3a5690c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19\n",
      "19\n"
     ]
    }
   ],
   "source": [
    "print(19)\n",
    "print(\"19\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "74256091",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_1 = 19\n",
    "age_2 = \"19\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6a827608",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(age_1,type(age_1))\n",
    "print(age_2,type(age_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e13fc08a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38\n"
     ]
    }
   ],
   "source": [
    "# 如果字符串是数值，可以用int转换成真正的数值\n",
    "if age_2.isdigit():\n",
    "    print(age_1 +int(age_2))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3c6d1cd2",
   "metadata": {},
   "source": [
    "## 2.有序的数据结构-列表（List)\n",
    "\n",
    "* 1. 列表的概念和基本性质\n",
    "> 1. Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type.\n",
    "* 2. 列表的一般方法（如何学习）\n",
    "> 1. 增加\n",
    "> 2. 删除\n",
    "> 3. 改\n",
    "> 4. 查：in\n",
    "* 列表的学习方法（步骤）\n",
    "> 1. 使用.Tab建查看列表的方法\n",
    "> 2. 使用help（查看方法的使用规则）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0d61b765",
   "metadata": {},
   "source": [
    "### 2.1 列表的性质\n",
    "* 和字符串的运算法则完全一致\n",
    "* 注意：字符串是对字符进行操作， 列表是对isdiget进行操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "523182e6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表的形式\n",
    "squares = [1,4,9,16,25] # 列表里面放数值\n",
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "7f9bb3ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "8cb6242e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4 in squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a66b1410",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares.count(9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "42a8d242",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 * squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "433e9d60",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'marry', 'jan', 'alex']"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"jack\",\"marry\",\"jan\",\"alex\"] # 列表里面放字符串\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "d3824fdf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'jan'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "b13ccd6d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'marry', 'jan']"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[0:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "20771d90",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'jan']"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出\"jack\",\"jan\"用切片的方法\n",
    "names[0:3:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "6ed52eb3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 'jack', 'marry', 'jan']"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares + names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "624c6e78",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 18, '李华', 20]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info = [\"jack\",18,\"李华\",20]\n",
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "24a9cd12",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.使用.Tab建查看列表的方法\n",
    "# 2.使用help（查看方法的使用规则）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "2699e95b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'marry', 'jan', 'alex']"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"jack\",\"marry\",\"jan\",\"alex\"]\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "bf0cff33",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "178c7d12",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Lihua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "cc165615",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'marry', 'jan', 'alex', 'Lihua']"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89d9b908",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
